package com.kgc.onlineLife.service.impl;

import com.kgc.onlineLife.bean.Category;
import com.kgc.onlineLife.bean.Product;
import com.kgc.onlineLife.bean.User;
import com.kgc.onlineLife.mapper.ProductMapper;
import com.kgc.onlineLife.service.ProductsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created On : 2022/4/15.
 * <p>
 * Author     : 张冲
 * <p>
 * Description: ProductsServiceImpl
 */
@Service
public class ProductsServiceImpl implements ProductsService {

    @Autowired
    private ProductMapper productMapper;

    /**
     * @author : 张冲
     * @date   : 2022/4/16
     * @param  : [cid]
     * @return : java.util.List<com.kgc.onlineLife.bean.Product>
     * @description : 通过分类查商品
     */
    @Override
    public List<Product> getProductsByCid(int cid) {
        List<Product> selectProductsByCid = productMapper.productList(cid);
        return selectProductsByCid;
    }

    /**
     * @author : 张冲
     * @date   : 2022/4/16
     * @param  : [id]
     * @return : com.kgc.onlineLife.bean.Product
     * @description : 通过id查商品详情
     */
    @Override
    public Product getProductsById(Integer id) {
        return productMapper.getProductDetail(id);
    }

    @Override
    public User getUserByBid(Integer bid) {
        return productMapper.getUser(bid);
    }

    @Override
    public Category getCategoryByCid(Integer cid) {
        return productMapper.getCategories(cid);
    }

    @Override
    public List<Product> selectProductDetailBySearchName(String searchName) {
        return productMapper.selectProductsBySearchName(searchName);
    }

    @Override
    public int selectTotalBySearchName(String searchName) {
        return productMapper.selectTotalBySearchName(searchName);
    }

    @Override
    public int selectCategoryTotalByCid(Integer cid) {
        return productMapper.selectTotalByCid(cid);
    }

    @Override
    public Product selectProductById(Integer id) {
        return productMapper.selectProductById(id);
    }
}
